package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.controller.BaseController;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.UserAccountDetail;
import com.bootdo.system.service.UserAccountDetailService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/sys/userAccountDetail")
@Controller
@Api(value = "/sys/userAccountDetail", description = "账户明细操作接口")
public class UserAccountDetailController extends BaseController {
	
	@Autowired
	UserAccountDetailService service;


	@ApiOperation(value="账户明细查询", notes="根据条件查询账户明细", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "账户明细id", required = false,paramType="query", dataType = "Long"),
        @ApiImplicitParam(name = "userId", value = "所属用户id", required = false,paramType="query", dataType = "Long"),
        @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true,paramType="query", dataType = "Integer"),
        @ApiImplicitParam(name = "pageNum", value = "当前页数", required = true,paramType="query", dataType = "Integer")
	})
	@GetMapping("/list")
	@ResponseBody
	R list(@RequestParam Map<String,Object> param)  throws Exception{
		Query query = new Query(param);
		List<UserAccountDetail> userAccountDetail = service.list(query);
		PageInfo<UserAccountDetail> pageInfo = new PageInfo<UserAccountDetail>(userAccountDetail);
		int total = (int)pageInfo.getTotal();
		PageUtils pageUtil = new PageUtils(userAccountDetail, total);
		return new R("list",pageUtil);
	}

	@ApiOperation(value="账户明细详情", notes="根据条件查询账户明细", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "账户明细id", required = true,paramType="query", dataType = "Long"),
	})
	@GetMapping("/edit")
	@ResponseBody
	R edit(Long id)  throws Exception{
		return new R("obj",service.get(id));
	}

	@ApiOperation(value="账户明细保存", notes="保存账户明细", response=String.class)
	@PostMapping("/save")
	@ResponseBody
	R save(@RequestBody UserAccountDetail baby)  throws Exception{
		if (service.save(baby) > 0) {
			return R.saveOk(baby.getId().toString());
		} else {
			return R.error(1, "保存失败");
		}
	}

	@ApiOperation(value="账户明细更新", notes="更新账户明细", response=String.class)
	@PostMapping("/update")
	@ResponseBody
	R update(@RequestBody UserAccountDetail baby)  throws Exception{
		if (service.update(baby) > 0) {
			return R.ok();
		} else {
			return R.error(1, "更新失败");
		}
	}

	@ApiOperation(value="账户明细删除", notes="根据账户明细id删除", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "账户明细id", required = true,paramType="query", dataType = "Long"),
	})
	@GetMapping("/remove")
	@ResponseBody
	R remove(Long id)  throws Exception{
		if (service.remove(id) > 0) {
			return R.ok();
		} else {
			return R.error(1, "删除失败");
		}
	}
	
	
}
